package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.model.domain.Question;
import com.tanhua.dubbo.mapper.QuestionMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * 7.通用——陌生人问题实现类
 */
@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    //根据用户ID查询陌生人问题
    @Override
    public Question findByUserId(Long userId) {
        QueryWrapper<Question> qw = new QueryWrapper<>();
        qw.eq("user_id", userId);
        return questionMapper.selectOne(qw);

    }

    //更新陌生人问题
    @Override
    public void update(Question question) {
        question.setUpdated(new Date());
        questionMapper.updateById(question);
    }

    //保存陌生人问题
    @Override
    public void save(Question question) {
        question.setCreated(new Date());
        question.setUpdated(new Date());
        questionMapper.insert(question);
    }
}